package com.example.anquan.Service;

import com.example.anquan.guanli.User;
import com.example.anquan.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserService implements UserDetailsService {
@Autowired
    UserRepository userRepository;

        @Override
        public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
                User user = userRepository.findByUsername(s);
                if(user == null){
                        throw new UsernameNotFoundException("用户不存在");
                }
                return user;
        }


        }
